package com.liyuan.yiqixing.dao;

import com.liyuan.yiqixing.model.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Repository
@Mapper
public interface AuthenticationDao {
    @Insert("insert into user(activeCode,account) values(#{activeCode},#{account})")
    void insertPreUser(User user);

    @Select("select * from user where account = #{account}")
    User retrieveUserByAccount(String account);

    @Insert("update user set role = #{role.id},password = #{password},nickname=#{nickname},avatarUrl=#{avatarUrl}")
    void insertUser(User user);

    @Select("select * from user where id = #{id}")
    User retrieveUserById(@Param("id") Integer id);

    @Update("update user set nickname=#{nickname},description=#{description} where id = #{id}")
    void updateUser(@Param("id") Integer id,
                    @Param("nickname") String nickname,
                    @Param("description") String description);

    @Select("select id,role,account,nickname,left(description,15) as description from user where id = #{userId}")
    User selectPartOfUser(@Param("userId") Integer userId);

    @Update("update user set avatarUrl = #{avatarUrl} where id = #{userId}")
    void updateUserAvatarUrl(@Param("userId") Integer userId,
                             @Param("avatarUrl") String avatarUrl);
}
